home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / darktown (FR).ifs < prev    next >
Encoding:
Text File  |  2004-06-14  |  8.4 KB  |  287 lines

  1. // GETINFO SCRIPTING
  2. // Darktown.com (module de recherche toute catΘgories)
  3.  
  4. (***************************************************
  5.  *  Script d'importation pour :                    *
  6.  *  Darktown , http://www.darktown.com             *
  7.  *                                                 *
  8.  *  Script by Doomer                               *
  9.  *  2004-06-10                                     *
  10.  *                                                 *
  11.  *  A utiliser avec Ant Movie Catalog 3.4.0        *
  12.  *  www.ant.be.tf/moviecatalog ╖╖╖ www.buypin.com  *
  13.  *                                                 *
  14.  *  The source code of the script can be used in   *
  15.  *  another program only if full credits to        *
  16.  *  script author and a link to Ant Movie Catalog  *
  17.  *  website are given in the About box or in       *
  18.  *  the documentation of the program               *
  19.  ***************************************************)
  20.  
  21. program DARKTOWN_SEARCH;
  22.  
  23. //ParamΦtres du script
  24. const
  25.  
  26.   TempsPause = 1500;      // 1000 = 1 Seconde (permet d'Θviter les timeout en cas de saturation serveur)
  27.   UrlStart = 'http://www.darktown.com/view.php?uid=';
  28.   UrlEnd = '"';
  29.  
  30.  
  31.  
  32. var
  33.   MovieName: string;
  34.   Page: TStringList;
  35.   Categorie : string;
  36.  
  37. {*
  38. Remplace le codage HTML par les caractΦres bizarres de la langue Allemande
  39. *}
  40. function HTMLReplace(Title: string): string;
  41. var
  42.   i: Integer;
  43. begin
  44.         Title := StringReplace(Title,'%20',' ');
  45.         Title := StringReplace(Title,'%26','&');
  46.         Title := StringReplace(Title,'%2F','/');
  47.         Title := StringReplace(Title,'%FC','ⁿ');
  48.         Title := StringReplace(Title,'%F6','÷');
  49.         Title := StringReplace(Title,'%22','"');
  50.         Title := StringReplace(Title,'%E4','Σ');
  51.         Title := StringReplace(Title,'%2C',',');
  52.         Title := StringReplace(Title,'%21','!');
  53.         Title := StringReplace(Title,'%2B','+');
  54.         Title := StringReplace(Title,'%B4','''');
  55.         Title := StringReplace(Title,'%D6','╓');
  56.         Title := StringReplace(Title,'%DF','▀');
  57.         Title := StringReplace(Title,'%C4','─');
  58.  
  59.         result := Title;
  60. end;
  61.  
  62. {*
  63. Cherche un ligne dans un tableau TStringList et retourne son indice
  64. *}
  65. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  66. var
  67.   i: Integer;
  68. begin
  69.   result := -1;
  70.   if StartAt < 0 then
  71.     StartAt := 0;
  72.   for i := StartAt to List.Count-1 do
  73.     if Pos(Pattern, List.GetString(i)) <> 0 then
  74.     begin
  75.       result := i;
  76.       Break;
  77.     end;
  78. end;
  79.  
  80. {*
  81. Compte les pages HTML α balayer pour lister toutes les rΘponses
  82. *}
  83. function PageCounter(address: string): Integer;
  84. var
  85. counter: Integer;
  86. BeginPos: Integer;
  87. EndPos: Integer;
  88.  
  89. begin
  90.   Page := TStringList.Create;
  91.   Page.Text := GetPage(Address);
  92.   Address := GetPage(Address);
  93.   BeginPos := Pos('/search.php?',Address);
  94.   delete(Address,1,BeginPos-1);
  95.   EndPos := Pos('"',Address);
  96.   Page.SetString(0,Copy(Address,1,EndPos-1));
  97.   delete(Address,1,9);
  98.   if (BeginPos > 0) then
  99.   begin
  100.     repeat
  101.       begin
  102.         counter := counter + 1;
  103.         BeginPos := Pos('/search.php?',Address);
  104.         Delete(Address,1,BeginPos-1);
  105.         EndPos := Pos('"',Address);
  106.         Page.SetString(counter,Copy(Address,1,EndPos-1));
  107.         delete(Address,1,9);
  108.       end;
  109.     until(BeginPos <= 0);
  110.   end
  111.     counter := (counter div 2);
  112.     result := counter;
  113. end;
  114.  
  115. {*
  116. m'a servi jadis au dΘbogage
  117. *}
  118. procedure testcounter(compteur: Integer);
  119. var
  120. i: Integer;
  121. begin
  122.   for i:=0 to compteur-1 do
  123.   ShowMessage(IntToStr(compteur) + Page.GetString(i));
  124. end;
  125.  
  126. {*
  127. Analyse le code HTML de la page pour remplir le PickTree
  128. *}
  129. procedure AnalyzePage(Address: string);
  130. var
  131.   LineNr: Integer;
  132.   BeginPos: Integer;
  133.   EndPos: Integer;
  134.   Element1: string;
  135.   Element2: string;
  136.   Element3: string;
  137.   Element4: string;
  138.   Title: string;
  139.   TitleAddr: string;
  140.   i: Integer;
  141.   BeginType: Integer;
  142.   BeginCat: Integer;
  143.   BeginName: Integer;
  144.   EndName: Integer;
  145.   stype: string;
  146.   sname: string;
  147.  
  148. begin
  149.   Sleep(TempsPause); // Attente X seconde : Evite les timeout sur le serveur
  150.   Element1 := 'href="';
  151.   Element2 := 'http://www.amazon.de/exec/obidos/external-search?tag=darktown0d-21&keyword=';
  152.   Element3 := 'index';
  153.   Element4 := '">';
  154.   LineNr := PageCounter(Address);
  155. //  testcounter(LineNr);
  156.   Address := GetPage(Address);
  157.   BeginPos := Pos(UrlStart,Address);
  158.   if BeginPos > 0 then
  159.   begin
  160.   PickTreeClear;
  161.  for i:=0 to LineNr do
  162.   begin
  163.   repeat
  164.     begin
  165.          delete(Address,1,BeginPos-1);
  166.         EndPos := Pos(UrlEnd,Address);
  167.         TitleAddr := Copy(Address,1,EndPos-1);
  168.          BeginName := Pos(Element1 + Element2,Address) + length(Element1 + Element2) - 1;
  169.          EndName := Pos('index=',Address);
  170.          sname := Copy(Address,BeginName+1,EndName-BeginName-2);
  171.          BeginType := Pos('type=',Address);
  172.          BeginCat := Pos('category=', Address);
  173.          stype := Copy(Address,Begintype+5,BeginCat-BeginType-6);
  174.         Title := sname + ' - ' + stype;
  175.         HTMLDecode(Title);
  176.         Title := HTMLReplace(Title);
  177.         delete(Address,1,length(UrlStart));
  178.         EndPos := Pos(Element4,Address);
  179.         PickTreeAdd(Title,TitleAddr);
  180.         BeginPos := Pos(UrlStart,Address);
  181.     end;
  182.   until (BeginPos <= 0);
  183.   if Pos('<html>', Page.GetString(i)) <=0 then
  184.      Address := GetPage(Page.GetString(i));
  185.   end
  186. if PickTreeExec(Address) then
  187. begin
  188.   Address := GetPage(Address);
  189.   BeginPos := Pos('<img src="http://img.darktown.com',Address);
  190.   delete(Address,1,BeginPos + 9);
  191.   EndPos := Pos('"',Address);
  192.   TitleAddr := Copy(Address,1,EndPos-1);
  193.   GetPicture(TitleAddr,false);
  194. end
  195. end;
  196. Page.Free;
  197. end;
  198.  
  199. {*
  200. retourne la catΘgorie de recherche pour le site Darktown
  201. *}
  202. function WhatCategorie(): string;
  203. var
  204. thecat : string;
  205. begin
  206.     PickTreeClear;
  207.     PickTreeAdd('Logiciels','anwender'); // ligne sΘlectionnΘe par dΘfaut
  208.     PickTreeAdd('Jeux','spiele');
  209.     PickTreeAdd('Audio','audio');
  210.     PickTreeAdd('PSX','psx');
  211.     PickTreeAdd('PS2','psx2');
  212.     PickTreeAdd('Dreamcast','dreamcast');
  213.     PickTreeAdd('XBox','xbox');
  214.     PickTreeAdd('GameCube','gamecube');
  215.     PickTreeAdd('DVD','dvd');
  216.     PickTreeAdd('VCD','vcd');
  217.     PickTreeAdd('VHS','vhs');
  218.     if PickTreeExec(thecat) then
  219.     begin
  220.       result := thecat
  221.     end
  222. end;
  223.  
  224. {*
  225. ne sert plus α rien, elle servait juste α remplir le champs pattern de la requΩte php
  226. *}
  227. function FindPage():string;
  228. var
  229.    CharCode : string;
  230. begin
  231.           CharCode := copy(MovieName,1,1);
  232.           case AnsiUpperCase(CharCode) of
  233.             'A': CharCode := 'A';
  234.             'B': CharCode := 'B';
  235.             'C': CharCode := 'C';
  236.             'D': CharCode := 'D';
  237.             'E': CharCode := 'E';
  238.             'F': CharCode := 'F';
  239.             'G': CharCode := 'G';
  240.             'H': CharCode := 'H';
  241.             'I': CharCode := 'I';
  242.             'J': CharCode := 'J';
  243.             'K': CharCode := 'K';
  244.             'L': CharCode := 'L';
  245.             'M': CharCode := 'M';
  246.             'N': CharCode := 'N';
  247.             'O': CharCode := 'O';
  248.             'P': CharCode := 'P';
  249.             'Q': CharCode := 'Q';
  250.             'R': CharCode := 'R';
  251.             'S': CharCode := 'S';
  252.             'T': CharCode := 'T';
  253.             'U': CharCode := 'U';
  254.             'V': CharCode := 'V';
  255.             'W': CharCode := 'W';
  256.             'X': CharCode := 'X';
  257.             'Y': CharCode := 'Y';
  258.             'Z': CharCode := 'Z';
  259.        else CharCode := '0-9';
  260.           end;
  261.       result := CharCode;
  262. end;
  263.  
  264. begin
  265.   if CheckVersion(3,4,0) then
  266.   begin
  267.     MovieName := GetField(fieldTranslatedTitle);
  268.     if MovieName = '' then
  269.       MovieName := GetField(fieldOriginalTitle);
  270.  
  271.     begin
  272.      if Input('Darktown.com Import', 'ElΘment de recherche :', MovieName) then
  273.       begin
  274.        // dans la requΩte de recherche les espaces sont remplacΘs par des +
  275.        MovieName := StringReplace(MovieName,' ','+');
  276.        // l'utilisateur doit sΘlectionner une catΘgorie de recherche
  277.        Categorie := WhatCategorie();
  278.        // on analyse le code des pages HTML pour remplir le PickTree
  279.        AnalyzePage('http://www.darktown.com/search.php?action=search&what=' + MovieName + '&&category='+Categorie+'&&submit=++SUCHE++');
  280.        // on affiche le rΘsultat
  281.        DisplayResults;
  282.       end;
  283.     end
  284.   end else
  285.    ShowMessage('Ce script requiert une version plus rΘcente de Ant Movie Catalog (au moins la version 3.4.0)');
  286. end.
  287.